<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="model.Item" %> 
<%@ page import="model.Size" %>
<%@ page import="model.Color" %>
<%@ page import="java.util.Set" %> 
<%@ page import="java.util.Map" %>   
<%@ page import="java.util.HashMap" %>   

 <% 
 	Item item = (Item) request.getAttribute("item");
 	Map<Integer, Color> idToColor = item.getIdToColor();
 	Map<Integer, Size> idToSize = item.getIdToSize();
 	Map<Integer,HashMap<Integer,Integer>>  colorIdToSizeIdToInventoryId = item.getColorIdToSizeIdsToInventoryId();
 	Set<Integer> colorIds = colorIdToSizeIdToInventoryId.keySet(); 	
 	Map<Integer,Integer> inventoryIdToCount = item.getInventoryIdToCount();
 	String description = item.getDescription();
 	int inventoryId;
	int count;
 %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Промяна на количества</title>
<link rel="stylesheet" href="/Store/css/Administration.css" type="text/css">
</head>
<body>
<div class="container">
<div class="main">
	<%=description %>
</div>
<form action="/Store/ChangeCounts" method="post" autocomplete="off">

<%for(int colorId : colorIds){
	 HashMap<Integer,Integer> sizeIdToInventoryId = colorIdToSizeIdToInventoryId.get(colorId);
	 Set<Integer> sizeIds = sizeIdToInventoryId.keySet();
%>
<div class="main">
	<table class="center">
		<tr>
			<td> Цвят:</td>  <td> <%=idToColor.get(colorId).getName() %> </td>
		</tr>
	<% for(int sizeId: sizeIds){
			inventoryId = sizeIdToInventoryId.get(sizeId);
			count = inventoryIdToCount.get(inventoryId);
	%>
		
		<tr>  
			<td> <%=idToSize.get(sizeId).getName() %></td> 
			<td> 
				<input type="number" min="0" name="counts[]" required value = <%=count %>>
			</td>
			<td> 
				<input  type="number" name="inventoryIds[]" value="<%=inventoryId %>" style="display: none">
			</td>
		</tr>
		
	<%}%>
	
	</table>

</div>

<% }%>
<div class="main"> 
	<table class="center">
		<tr>
			<td> <input type="submit" value="Продължи"></td>
			<td class="cancel"> <a href="/Store/Supplier.html"> <button type="button"> Отмени </button> </a></td>
		</tr>
	</table>
</div>
</form>

</div>
</body>
</html>